home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / prog / basic / param.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.1 KB  |  100 lines

  1. #include <LEDA/list.h>
  2. #include <LEDA/array.h>
  3.  
  4.  
  5. // Any built-in, pointer, item, or user-defined class type can be used 
  6. // as actual type parameter for a parameterized data type. Class types T
  7. // have to provide the following operations:
  8. // 
  9. // a constructor taking no arguments   T::T()
  10. // a copy constructor                  T::T(const T&)
  11. // a Read function                void Read(T&, istream&)
  12. // a Print function               void Print(const T&, ostream&)
  13. // 
  14. // A compare function  "int compare(const T&, const T&)" has to be defined 
  15. // if required by the data type.
  16.  
  17.  
  18. class d3_point
  19. {
  20.    float x;
  21.    float y;
  22.    float z;
  23.  
  24.  
  25.    public:
  26.  
  27.    d3_point(float a=0, float b=0, float c=0) { x = a;   y = b;   z = c; }
  28.    d3_point(const d3_point& p)                  { x = p.x; y = p.y; z = p.z; }
  29.  
  30.  
  31.    LEDA_MEMORY(d3_point);
  32.  
  33.    friend istream& operator>>(istream& I, d3_point& p);
  34.    friend ostream& operator<<(ostream& O, const d3_point& p);
  35.    friend int      compare(const d3_point& p, const d3_point& q);
  36.  
  37. };
  38.  
  39. istream& operator>>(istream& I, d3_point& p) 
  40. { return I >> p.x >> p.y >> p.z;}
  41.  
  42. ostream& operator<<(ostream& O, const d3_point& p)
  43. { return O << "(" << p.x << "," << p.y << "," << p.z << ")"; }
  44.  
  45.  
  46. void Read(d3_point& p, istream& I)        { I >> p; }
  47.  
  48. void Print(const d3_point& p, ostream& O) { O << p; }
  49.  
  50. int compare(const d3_point& p, const d3_point& q)  // lexicograph.
  51. { int b;
  52.   if (b=compare(p.x,q.x)) 
  53.      return b;
  54.   else 
  55.      if (b=compare(p.y,q.y)) 
  56.         return b;
  57.      else 
  58.         return compare(p.z,q.z); 
  59. }
  60.  
  61.  
  62. #if !defined(__TEMPLATE_FUNCTIONS__)
  63. LEDA_TYPE_PARAMETER(d3_point)
  64. LEDA_TYPE_PARAMETER(list<d3_point>)
  65. #endif
  66.  
  67. void Print(const list<d3_point>& L, ostream& O) { L.print(O); }
  68.  
  69. typedef list<d3_point> LLL;
  70.  
  71. main()
  72. {
  73.   array<list<d3_point> > A(1,5);
  74.  
  75.   // array<LLL>  A(1,5);
  76.  
  77.  
  78.   for(int i=1;i<=5;i++) A[i].read(string("List[%d]: ",i));
  79.   newline;
  80.  
  81.   A.print("input:",'\n');
  82.   newline;
  83.   newline;
  84.  
  85.   for(i=1;i<=5;i++) A[i].permute();
  86.   A.permute();
  87.  
  88.   A.print("permuted:",'\n');
  89.   newline;
  90.   newline;
  91.  
  92.   for(i=1;i<=5;i++) A[i].sort();
  93.  
  94.   A.print("sorted:",'\n');
  95.   newline;
  96.   newline;
  97.  
  98.   return 0;
  99.  }
  100.